package servletUser;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * Created by Administrator on 2020/12/4.
 */
public class ResponseIOServlet extends HttpServlet{
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1. 设置服务器字符集
        resp.setCharacterEncoding("UTF-8");
        //通过响应头设置浏览器字符集
        resp.setHeader("Content-Type","text/html;charset=UTF-8");

        //2. 同时设置字符集
        //必须在获取字符流之前设置
//        resp.setContentType("text/html; charset=UTF-8");

        PrintWriter writer = resp.getWriter();
        //之后无效
        //resp.setContentType("text/html; charset=UTF-8");
        writer.write("加油！");

    }



}
